<?php

use yii\db\Migration;

class m170511_075712_init_create_news_module_tables extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
        }
        //1.创建栏目表
        $this->createTable('ts_news_banners', [
            'id' => $this->primaryKey(),
            'name' => $this->string(50)->notNull()->comment('栏目名称'),
            'create_at' => $this->datetime()->comment('添加时间'),
            'banner_type'=>$this->smallInteger()->unsigned()->defaultValue(1)->comment('栏目类型'),
            'order' => $this->smallInteger()->unsigned()->defaultValue(0)->comment('排序'),
            'corpid' => $this->string(18)->defaultValue('')->comment('企业id'),
            ], $tableOptions);
        $this->createIndex('corpid','ts_news_banners','corpid');
        //2.创建文章表
        $this->createTable('ts_news_articals', [
            'id' => $this->primaryKey(),
            'banner_id'=>$this->Integer()->unsigned()->notNull()->comment('栏目id'),
            'author' => $this->string(30)->notNull()->comment('作者'),
            'title'=>$this->string(30)->notNull()->comment('文章题目'),
            'img'=>$this->Integer()->unsigned()->notNull()->comment('图文中的图片'),
            'artical'=>$this->text()->comment('文章内容'),
            'create_at' => $this->datetime()->comment('添加时间'),
            'issue'=>$this->smallInteger()->unsigned()->defaultValue(0)->comment('是否发布'),
            'order' => $this->smallInteger()->unsigned()->defaultValue(0)->comment('排序'),
            'click' => $this->Integer()->unsigned()->defaultValue(0)->comment('点击量'),
            'corpid' => $this->string(18)->defaultValue('')->comment('企业id'),
            ], $tableOptions);
        $this->createIndex('corpid','ts_news_articals','corpid');
    }

    public function down()
    {
        echo "m170511_075712_init_create_news_module_tables cannot be reverted.\n";
        $this->dropTable('ts_news_articals');
        $this->dropTable('ts_news_banners');
    }

    /*
    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
    }

    public function safeDown()
    {
    }
    */
}
